package com.x_memteor.base_master.bean.request;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.x_memteor.base_master.base.BaseRequestEntity;
import com.x_memteor.base_master.utils.AesEncodeUtil;
import com.x_memteor.base_master.utils.GsonUtils;
import com.x_memteor.base_master.utils.LogUtils;

/**
 * @author: X_Meteor
 * @description: 类描述
 * @version: V_1.0.0
 * @date: 2018/2/28 0028 下午 8:56
 * @company:
 * @email: lx802315@163.com
 */
public class TokenBody extends BaseRequestEntity implements Parcelable {

    /**
     * time : 1517906386
     * mac : 10:a4:be:5f:40:27
     */

    private long time;
    private String mac;

    public String getMac_code() {
        return mac_code;
    }

    public void setMac_code(String mac_code) {
        this.mac_code = mac_code;
    }

    public String getVersion_id() {
        return version_id;
    }

    public void setVersion_id(String version_id) {
        this.version_id = version_id;
    }

    private String mac_code;
    private String version_id;
    private String sign;
    private String ciphertext;

    Gson mGson;

    @Override
    public String getSign() {
        if (mGson == null) {
            mGson = GsonUtils.getInstance();
        }
        if (TextUtils.isEmpty(sign)) {
            sign = AesEncodeUtil.encrypt(mGson.toJson(this));
        }
        LogUtils.print(AesEncodeUtil.decrypt(sign));
        return sign;
    }

    public TokenBody(long time, String mac) {
        this.time = time;
        if (String.valueOf(time).length() > 10) {
            this.time = Long.valueOf(String.valueOf(time).substring(0, 10));
        }
        this.mac = mac.toLowerCase();
    }

    @Override
    public String getCiphertext() {
        if (mGson == null) {
            mGson = GsonUtils.getInstance();
        }
        if (TextUtils.isEmpty(ciphertext)) {
            ciphertext = AesEncodeUtil.encrypt(mGson.toJson(this));
        }
        return ciphertext;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.time);
        dest.writeString(this.mac);
    }

    public TokenBody() {
    }

    protected TokenBody(Parcel in) {
        this.time = in.readLong();
        this.mac = in.readString();
    }

    public static final Parcelable.Creator<TokenBody> CREATOR = new Parcelable.Creator<TokenBody>() {
        @Override
        public TokenBody createFromParcel(Parcel source) {
            return new TokenBody(source);
        }

        @Override
        public TokenBody[] newArray(int size) {
            return new TokenBody[size];
        }
    };
}
